<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="domain.entity.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path;
	ServletContext context = pageContext.getServletContext();
	SysUser user = (SysUser)context.getAttribute("user");
%>
<div style="height:100%; width:100%;">
    <table style=" height:100%; width:100%;border:1px;border-color:black">
        <tr>
            <td style="width:100%">
                <table style="height: 100%; width: 100%">
                    <tr style="height: 30%; border-bottom-width: 1px; border-bottom-color: gray; border-bottom-style: solid; height: 18em; ">
                        <td></td>
                        <td>
                            <div style="width: 100%">
                                <table style="width: 100%;line-height: 24px" class="form-table">
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">当前账号    :</td>
                                        <td>
                                            <input class="easyui-textbox" name="txtcuraccount" id="txtcuraccount" type="text">
                                        </td>
                                    </tr>

                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">原始密码<span style=" color: red">*</span>:</td>
                                        <td>
                                            <input class="easyui-textbox" name="txtoriginalpassword" id="txtoriginalpassword" type="password">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">最新密码<span style=" color: red">*</span>:</td>
                                        <td>
                                            <input class="easyui-textbox" name="txtnewpassword" id="txtnewpassword" type="password">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">确认密码<span style=" color: red">*</span>:</td>
                                        <td>
                                            <input class="easyui-textbox" name="txtsurepassword" id="txtsurepassword" type="password">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label"></td>
                                        <td>
                                            <div id="divpower">
                                                <a href="javascript:savePwdData()" class="easyui-linkbutton" style=" width:80px" id="btnSave">保存</a>
                                            </div>
                                        </td>
                                    </tr>

                                </table>
                            </div>
                        </td>
                        <td></td>
                    </tr>
                </table>
            </td>
        </tr>

    </table>
</div>
<script src="<%=basePath%>/Scripts/md5.js"></script>
<script type="text/javascript">
    $(function () {
        $.parser.onComplete = function () {
            $("#txtcuraccount").textbox('setValue', "<%=user.getLoginName()%>");
        };
        $("#txtcuraccount").attr({ readonly: 'true' });
    });
    function savePwdData()
    {
        if ($("#txtoriginalpassword").val().trim() == "") {
            ERP_alert("原始密码不能为空!");
            return;
        }

        if (MD5($("#txtoriginalpassword").val().trim()) != "<%=user.getPassword()%>") {
            ERP_alert("原始密码错误!");
            return;
        }
        
        if ($("#txtnewpassword").val().trim() == "")
        {
            ERP_alert("新密码不能为空!");
            return;
        }
        if ($("#txtsurepassword").val().trim() == "") {
            ERP_alert("确认密码不能为空!");
            return;
        }
        if ($("#txtnewpassword").val().search(/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/) == -1) {
            ERP_alert("新密码须字母开头，5-16字符，允许字母数字下划线!");
            return;
        }
        if ($("#txtnewpassword").val().trim() != $("#txtsurepassword").val().trim())
        {
            ERP_alert("两次密码输入不一致!");
            return;
        }

        var postdata = {
            newpwd: MD5($("#txtnewpassword").val().trim())
        };

        $.post("<%=basePath%>/system/user/savePwdData", postdata, function (data) {
            if(data== "")
            {
                ERP_alert('修改成功');
                $("#txtoriginalpassword").val($("#txtnewpassword").val().trim());
                InitUserData();
            }
            else
            {
                ERP_alert(data);
            }
        });
    }

    function InitUserData()
    {
        $("#txtcuraccount").textbox('setValue', "@Model.LoginName");
        $("#txtnewpassword").textbox('setValue', "");
        $("#txtsurepassword").textbox('setValue', "");
    }
</script>

